index.js ➔ importAll   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
const providers = {}
2
3
// load all files from ./Providers folder into providers variable
4
function importAll (moduleRequire) {
5
  moduleRequire.keys().forEach(key => {
6
    providers[key.substr(2, key.length - 5)] = moduleRequire(key).init
7
  })
8
}
9
importAll(require.context('./Providers/', true, /\.js$/))
10
11
let instance
12
13
class ExternalScriptLoader {
14
  constructor () {
15
    console.warn('ExternalScriptLoader is deprecated since version 1.4.0 with no alternative available.')
16
    if (!instance) {
17
      instance = this
18
    }
19
    return instance
0 ignored issues
show
Bug introduced by
The constructor does not have a meaningful return value. Are you sure this is correct?
Loading history...
20
  }
21
22
  static getInstance () {
23
    return instance || new ExternalScriptLoader()
24
  }
25
26
  initialize (type, options = {}) {
27
    if (!this[type]) {
28
      this[type] = providers[type](options)
29
    }
30
    return this[type]
31
  }
32
}
33
34
window.FlyntExternalScriptLoader = ExternalScriptLoader
35